package com.bjpowernode.app;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.File;
import java.util.ArrayList;
import java.util.LinkedList;

public class MyApp8 {

    LinkedList<Node> linkedList = new LinkedList<>();

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    //节点类型
    public static class Node {
        String name;
        Node parent;
    }


    //递归父亲入栈
    private void getPath(Node node) {
        Node parent = node.getParent();
        if (parent != null) {
            linkedList.push(parent);
            getPath(parent);
        }
    }

    public String execute(Node node) {
        //把自己入栈
        linkedList.push(node);
        //把父入栈
        getPath(node);
        //出栈
        StringBuffer stringBuffer = new StringBuffer();
        while (linkedList.peek() != null) {
            Node pop = linkedList.pop();
            stringBuffer.append(pop.getName());
            stringBuffer.append(File.separator);
        }
        return stringBuffer.toString();
    }


    public static void main(String[] args) {
        //创建节点
        Node nodeSrc = new Node("src", null);
        Node nodeMain = new Node("main", nodeSrc);
        Node nodeTest = new Node("test", nodeSrc);
        Node nodeJava = new Node("java", nodeMain);
        Node nodeResources = new Node("resources", nodeMain);
        Node nodeCom = new Node("com", nodeJava);
        Node nodeBjpowernode = new Node("bjpowernode", nodeCom);
        Node nodeBeans = new Node("beans", nodeBjpowernode);
        Node nodeMapper = new Node("mapper", nodeBjpowernode);

        ArrayList<Node> nodes = new ArrayList<>();
        nodes.add(nodeSrc);
        nodes.add(nodeMain);
        nodes.add(nodeTest);
        nodes.add(nodeJava);
        nodes.add(nodeResources);
        nodes.add(nodeCom);
        nodes.add(nodeBjpowernode);
        nodes.add(nodeBeans);
        nodes.add(nodeMapper);

        MyApp8 myApp8 = new MyApp8();
        for (Node node : nodes) {
            String execute = myApp8.execute(node);
            execute = "d:\\web1\\" + execute;
            File file = new File(execute);
            boolean mkdirs = file.mkdirs();
            if (mkdirs) {
                System.out.println(execute + "创建成功...............");
            } else {
                System.out.println(execute + "创建失败*************************");
            }
        }
    }


}
